package com.example.danmu;

import top.wecreate.view.DanmakuView;
import top.wecreate.view.DanmakuView.ScreenStyle;
import top.wecreate.view.RoomSendMessageInfo;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;

import com.example.dynamicmain.R;

public class DanmuActivity extends Activity {

	DanmakuView danmuView;

	boolean port = true;
	boolean hasInit = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_danmu);
		danmuView = (DanmakuView) findViewById(R.id.danmuview);
		danmuView.getViewTreeObserver().addOnGlobalLayoutListener(
				new OnGlobalLayoutListener() {

					@Override
					public void onGlobalLayout() {
						if (!hasInit) {
							hasInit = true;
							danmuView.setScreenStyle(ScreenStyle.PORT);
						}

					}
				});
		findViewById(R.id.screen_style).setOnClickListener(
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						port = !port;
						danmuView.setScreenStyle(port ? ScreenStyle.LAND
								: ScreenStyle.PORT);
					}
				});
		findViewById(R.id.add).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				RoomSendMessageInfo info = new RoomSendMessageInfo();
				info.setContent("手动测试__aa_ " + (i++));
				danmuView.setData(info);
			}
		});
		findViewById(R.id.lock).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				RoomSendMessageInfo info = new RoomSendMessageInfo();
				info.setContent("锁屏！！！！！ ");
				danmuView.lockScreen(info);
			}
		});
		findViewById(R.id.unlock).setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				RoomSendMessageInfo info = new RoomSendMessageInfo();
				info.setContent("解除锁屏！！！！！ ");
				danmuView.unlockScreen(info);

			}
		});
		danmuView.start();
	}
	
	private int i = 0;
}
